package gu;

import java.io.IOException;

import org.jsoup.Connection;
import org.jsoup.HttpStatusException;
import org.jsoup.Jsoup;
import org.jsoup.Connection.Method;
import org.jsoup.nodes.Document;
 
public class HttpManager4Process extends HttpManager {
	private static Connection.Response LoginResponse=null;
	
	public void Login(String LoginURL, String LoginInfo, String formName) {
		String[] logarr = LoginInfo.split(",");
		
		try {
			LoginResponse = Jsoup.connect(LoginURL)
					.data(logarr)
					.method(Method.POST)
					.execute();
		} catch (HttpStatusException  e) {
			System.out.println( e);
       	} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public Document GetDocument(String targetURL){
		Document doc=null;
		responseCode = 200;
		long startTime = System.currentTimeMillis();  // elapse time
		try {
			if (LoginResponse==null)
				 doc = Jsoup.connect(targetURL).timeout(0).get();
			else doc = Jsoup.connect(targetURL).timeout(0).cookies(LoginResponse.cookies()).get();
			responseTime = System.currentTimeMillis() - startTime;		// elapse time
		} catch (HttpStatusException  e) {
			//e.printStackTrace();
			responseCode = e.getStatusCode();
			responseTime = 0;
       	} catch (IOException e) {
			e.printStackTrace();
		}
		
		return doc; 
	}

}
